home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / Z4Z5EX.C < prev    next >
C/C++ Source or Header  |  1993-07-02  |  5KB  |  153 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    z4z4ex.c
  5. //   Title:    ZIP+4 Engine
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains the expander for the ZIP5 file.
  25. //    This module should not use any global variables since it must be 
  26. //    re-entrant.
  27. //
  28. //    The code in this module should be written entirely in C. 
  29. //    Do not use any C++ constructs.
  30. //
  31. //    This module is portable to:
  32. //        DOS 3.X+
  33. //        MS Windows 3.X+
  34. //        OS/2 2.X+
  35. //        OS/2 2.0 PM
  36. //        SCO UNIX.
  37. //
  38. //    The following compilers are supported:
  39. //        MSC 6.0A
  40. //        MSC/C++ 7.0
  41. //        Borland C++ 3.1 for DOS
  42. //        Borland C++ 1.0 for OS/2 2.X
  43. //        SCO UNIX cc
  44. //
  45. //----------------------------------------------------------------------------
  46. #include <z4.h>
  47.  
  48.  
  49. //----------------------------------------------------------------------------
  50. //   Description:    Read a compressed record from the output buffer.
  51. //    Parameters: pblk            Decoder data structure
  52. //                        pctyst        ZIP5 record
  53. //       Returns:    TRUE if successful. 
  54. //                        FALSE if no more records found to decode.
  55. //----------------------------------------------------------------------------
  56. BOOL FN_E Z4Z5Expand(PZ4_Z5_BLK pblk, PZ4_Z5 pz5)
  57. {
  58.     PBYTE pb;
  59.     SIZET cb;
  60.  
  61.     Assert(pblk && pz5);
  62.     memset(&pblk->z5, 0, sizeof(pblk->z5));
  63.                                                     // Must be at end of buffer
  64.     if (pblk->cbNext + MAX_ZIP5_BCD + sizeof(USHORT) >= pblk->cb)
  65.         return FALSE;
  66.  
  67.     pb = pblk->pb + pblk->cbNext;            // Decode ZIP5
  68.     if (pb[0] == 0)                            // Block not full, but no more records
  69.         {
  70.         pblk->cbNext = pblk->cb;
  71.         return FALSE;
  72.         }
  73.     strb2a(pb, MAX_ZIP5_BCD, pblk->z5.szZip5, MAX_ZIP5, TRUE);
  74.     pb += MAX_ZIP5_BCD;
  75.  
  76.     strb2a(pb, MAX_FINANCE_BCD, pblk->z5.szFinance, MAX_FINANCE, TRUE);
  77.     pb += MAX_FINANCE_BCD;
  78.                                                     // ZIP5 was zero -- no more records
  79.     if (strcmp(pblk->z5.szZip5, "00000") == 0)
  80.         return FALSE;
  81.  
  82.     cb = (SIZET)(pb[0] & 0x7F);
  83.     if (pb[0] & 0x80)
  84.         {
  85.         pb++;
  86.         cb += (((SIZET)pb[0]) << 7);
  87.         pb++;
  88.         }
  89.     else
  90.         pb++;
  91.     cb++;
  92.  
  93.     if (!RecIdDecode(pblk->z5.arecid, MAX_ZIP5_CITIES, pb, cb, &pblk->z5.cCities, &pblk->recid))
  94.         return FALSE;
  95.     Assert(pblk->z5.cCities <= MAX_ZIP5_CITIES);
  96.     pb += cb;
  97.  
  98.     cb = (SIZET)(pb - pblk->pb);
  99.     Assert(cb <= pblk->cb);
  100.     pblk->cbNext = cb;
  101.     *pz5 = pblk->z5;                            // Return a copy of the current record
  102.     return TRUE;
  103. }
  104.  
  105.  
  106. //----------------------------------------------------------------------------
  107. //   Description:    Initialize ZIP5 expander
  108. //    Parameters:    pblk            Decoder data structure
  109. //       Returns:    TRUE if successful.
  110. //----------------------------------------------------------------------------
  111. BOOL FN_E Z4Z5ExpandInitialize(PZ4_Z5_BLK pblk)
  112. {
  113.     Assert(pblk);
  114.     memset(pblk, 0, sizeof(Z4_Z5_BLK));
  115.     return TRUE;
  116. }
  117.  
  118.  
  119. //----------------------------------------------------------------------------
  120. //   Description:    Reset ZIP5 expander to decode another block of data.
  121. //    Parameters:    pblk            Decoder data structure
  122. //                        pb                Buffer containing compressed data.
  123. //                        cb                Size of buffer.
  124. //       Returns:    TRUE if successful.
  125. //----------------------------------------------------------------------------
  126. BOOL FN_E Z4Z5ExpandReset(PZ4_Z5_BLK pblk, PBYTE pb, SIZET cb)
  127. {
  128.     Assert(pblk);
  129.     pblk->pb = pb;                                // Set decoding pointers
  130.     pblk->cb = cb;
  131.     pblk->cbNext = 0;
  132.     pblk->recid.usOffset = 0;
  133.     pblk->recid.lBlock = 0;
  134.     return TRUE;
  135. }
  136.  
  137.  
  138. //----------------------------------------------------------------------------
  139. //   Description:    Terminate ZIP5 expander.
  140. //    Parameters:    pblk        Decoder data structure
  141. //       Returns:    TRUE if successful.
  142. //----------------------------------------------------------------------------
  143. BOOL FN_E Z4Z5ExpandTerminate(PZ4_Z5_BLK pblk)
  144. {
  145.     Assert(pblk);
  146.     memset(pblk, 0, sizeof(Z4_Z5_BLK));
  147.     return TRUE;
  148. }
  149. //----------------------------------------------------------------------------
  150. //------------------------------- End of File --------------------------------
  151. //----------------------------------------------------------------------------
  152.  
  153.